<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery-1.10.0.js"></script>
<script type="text/javascript" src="js/jquery.validate-1.13.1.js"></script>
<title>德库树研发一部</title>

<script type="text/javascript">
	$(document).ready(function () {
       	$("#connectionform").validate({
            rules: {
            	url: {
                    required: true
                },
                username: {
                    required: true
                },
                password: {
                    required: true
                }
            },
            messages: {
            	url: {
                    required: '请输入数据库地址'
                },
                username: {
                    required: '请输入用户名'
                },
                password: {
                    required: '请输入密码',
                }
            },
            highlight: function(element, errorClass, validClass) {
                $(element).addClass(errorClass).removeClass(validClass);
                $(element).fadeOut().fadeIn();
            },
            unhighlight: function(element, errorClass, validClass) {
                $(element).removeClass(errorClass).addClass(validClass);
            },
            submitHandler: function (form) {
                //console.log($(form).serialize());
            }
        });
		
		$("#codeform").validate({
            rules: {
            	packagename: {
                    required: true
                },
                modelname: {
                    required: true
                }
            },
            messages: {
            	packagename: {
                    required: '请输入packagename'
                },
                modelname: {
                    required: '请输入modelname'
                },
            },
            highlight: function(element, errorClass, validClass) {
                $(element).addClass(errorClass).removeClass(validClass);
                $(element).fadeOut().fadeIn();
            },
            unhighlight: function(element, errorClass, validClass) {
                $(element).removeClass(errorClass).addClass(validClass);
            },
            submitHandler: function (form) {
            	form.submit();
            }
        });

		$("#getTables").click(function(){
			var url = $("#url").val();
			var pas = $("#password").val();
			var usr = $("#username").val();
			$.post('<%=basePath%>getTargetDatabaseTables.action',{url:url,usr:usr,pas:pas},function(data){
				$("#label_table").html('<tr><td class="width_50">序号</td><td class="width_140">表名</td><td class="width_140">备注</td><td class="width_140">主键</td></tr>');
				$.each(data,function(i,n){
					$("#label_table").append('<tr><td class="width_50"><input type="radio" name="tableid" style="min-width:50px;" id="'+i +'" value="'+n.tableName+'"/></td><td class="width_140"><label>'
							+ n.tableName+'</label></td><td class="width_140"><label>'
							+ n.tableDesc +'</label></td><td class="width_140"><label>'
							+ n.key +'</label></td></tr>');
				});
			});
		});
		
		$("#getcode").click(function(){
			var table= $("input[name=tableid]:checked");
        	var tablename= table.val();
			if(tablename == '' || tablename==null || tablename=='undefined'){
				alert('请选择一张表');
				return;
			}
			var keyname= $(table).parent().siblings();
			$("#c_table").val(tablename);
			$("#c_url").val($("#url").val());
			$("#c_user").val($("#username").val());
			$("#c_pass").val($("#password").val());
			$("#c_style").val($("input[name=codestyle]:checked").val());
			$("#c_id").val($(keyname[2]).children('label').text());
			$("#codeform").submit();
		});

		$("#packagename").keyup(function(){
			getNames($(this).val(), $("#modelname").val());
		});

		$("#modelname").keyup(function(){
			getNames($("#packagename").val(),$(this).val());
		});


    });

	function getNames(packagename,modelname){
		if(packagename!='' && packagename !=null && packagename != 'undefined' &&
			modelname!='' && modelname !=null && modelname != 'undefined'){
			$.post('<%=basePath%>getNames.action', {
				packagename : packagename,
				modelname : modelname
			}, function(data) {
				$("#modelName").text(data.modelName);
				$("#daoName").text(data.daoName);
			});
		}

	}
</script>
<style type="text/css">
body {
	background-color: #ccc;
	line-height: 1.6;
	margin-left: 80px;
}

input {
	font-size: 25px;
	line-height: 35px;
	border: 1px solid #999;
	min-width: 180px;
}

button {
	margin-top: 20px;
	font-size: 20px;
	padding: 5px;
}

label.error {
	margin-left: 10px;
	color: red;
}

.showname {
	font-size: 20px;
	font-weight: bold;
}

.showname span {
	color: red;
}

.tablediv {
	float: left;
	width: 45%;
}

.tablediv table {
	border-collapse: collapse;
	border: 1px solid #000;
	font-size: 13px;
}

.tablediv table tr td {
	border: 1px solid #000;
	margin: 5px;
}

.width_50 {
	width: 50px;
}

.width_140 {
	width: 200px;
}

.helpdiv {
	float: left;
	margin-left:10px;
	width: 300px;
	height: 400px;
}
</style>
</head>
<body>
	<h1>德库树-研发一部欢迎你</h1>
	<form id="connectionform">
		<label>db url:</label> <input type="text" id="url" name="url"
			value="jdbc:oracle:thin:@10.10.2.40:1521:stateunion" size="45">
		<input type="submit" value="获取TABLE" id="getTables" />
		<table>
			<tr>
				<td><label>username:</label></td>
				<td><input type="text" id="username" name="username"
					value="syw" size="10"></td>

				<td><label>password:</label></td>
				<td><input type="text" id="password" name="password"
					value="syw" size="10"></td>

			</tr>
		</table>
	</form>
	<form id="codeform" action="<%=basePath%>getCode.action" method="post">
		<table>
			<tr>
				<td><label>package:</label></td>
				<td><input type="text" id="packagename" name="packagename"></td>
				<td><label>module:</label></td>
				<td><input type="text" id="modelname" name="modelname"></td>
				<td><input type="submit" value="获取CODE" id="getcode" /></td>
			</tr>
		</table>
		<input type="hidden" id="c_url" name="c_url"> 
		<input type="hidden" id="c_user" name="c_user"> 
		<input type="hidden" id="c_pass" name="c_pass"> 
		<input type="hidden" id="c_table" name="c_table">
		<input type="hidden" id="c_style" name="c_style">
		<input type="hidden" id="c_id" name="c_id">
	</form>

	<div>
		<input type="radio" name="codestyle" value="1" checked="checked" style="min-width: 30px;"><label class="showname">普通方式</label> 
		<input type="radio" name="codestyle" value="2" style="min-width: 30px;"><label class="showname">读写方式</label>
		<br>
		<label class="showname">Model Class：<span id="modelName"></span></label>
		<br> <label class="showname">Dao Class：<span id="daoName"></span></label>
	</div>

	<div class="tablediv">
		<table id="label_table">
			<tr>
				<td class="width_50">序号</td>
				<td class="width_140">表名</td>
				<td class="width_140">备注</td>
				<td class="width_140">主键</td>
			</tr>
		</table>
	</div>

	<div class="helpdiv">
		<h2>常用工具下载</h2>
		<table>
			<tr>
				<td><a href="/upload/apache-maven-3.2.5.rar">maven 3.2.5</a></td>
				<td><a href="/upload/eclipse.rar">ecplise</a></td>
				<td><a href="/upload/jdk-7u67-windows-x64.exe">JDK1.7</a></td>
			</tr>
			<tr>
				<td><a href="/upload/apache-tomcat-7.0.59.rar">tomcat 7.0</a></td>
				<td><a href="/upload/em263_setup.rar">263EM</a></td>
				<td><a href="/upload/ps-pulse-win-5.1r1.1-b52267-64bitinstaller.msi">VPN拨号软件</a></td>
			</tr>
			
			<tr>
				<td><a href="/upload/memcached_jb51.rar">memcached1.4.4</a></td>
				<td><a href="/upload/redis-2.4.5-win32-win64.rar">redis2.4.5</a></td>
			</tr>
		</table>


		<h2>规范文档</h2>
		<table>
			<tr>
				<td><a href="/upload/docs/新版规范文档（20150816版）.rar">德库树研发一部开发规范</a></td>
			</tr>
			<tr>
				<td><a href="/upload/docs/codeformat.rar">java代码格式化模板</a></td>
			</tr>
			<tr>
				<td><a href="/upload/docs/版本提交通知单_模板.doc">版本提交通知单_模板.doc</a></td>
			</tr>
			<tr>
				<td><a href="/upload/docs/数银网基金1.0.0.1-realease安装部署手册.docx">安装部署手册_模板.doc</a></td>
			</tr>
			<tr>
				<td><a href="/upload/docs/德库树-ppt模版.ppt">德库树-ppt模版.ppt</a></td>
			</tr>
			<tr>
				<td><a href="/upload/docs/【xxx】研发一部-11月绩效考核表 - 模板.xls">月绩效考核表-模板</a></td>
			</tr>
			<tr>
				<td><a href="/upload/docs/安全设计与研发.rar">安全设计与研发</a></td>
			</tr>
		</table>



		<h2>培训ppt</h2>
		<table>
			<tr>
				<td><a href="/upload/ppts/jenkins持续集成工具的构建和使用.ppt">Jenkins自动化构建和部署.ppt</a></td>
			</tr>
			<tr>
				<td><a href="/upload/ppts/JVM优化与代码分析.ppt">JVM优化与代码分析.ppt</a></td>
			</tr>
			<tr>
				<td><a href="/upload/ppts/Dubbo架构.pptx">Dubbo架构.pptx</a></td>
			</tr>
			<tr>
				<td><a href="/upload/ppts/JqueryMobile手机网站开发.rar">JqueryMobile手机网站开发.rar</a></td>
			</tr>
			<tr>
				<td><a href="/upload/ppts/网页布局与内容解耦合-原文龙.pptx">网页布局与内容解耦合-原文龙.pptx</a></td>
			</tr>
			<tr>
				<td><a href="/upload/ppts/Jeecms介绍及使用.ppt">Jeecms介绍及使用.ppt</a></td>
			</tr>
			<tr>
				<td><a href="/upload/ppts/基于lucene的站内全文检索.ppt">基于lucene的站内全文检索.ppt</a></td>
			</tr>
		</table>
	</div>

</body>
</html>